
CC = g++
CFLAGS = -O2
CPPFLAGS =
LIBS = -lmysqlcppconn -lboost_system -lboost_thread -llua

LIB_DIR = -L./lib/boost -L./lib/mysqlcpp -L./lib/lua
INC_DIR = -I./include -I./include/mysqlcpp -I./include/lua -I./src/common -I./src/xdata_server -I./src/xgame_server -I./src/xgate_server

common_obj = $(patsubst %.cpp, %.o, $(wildcard ./src/common/*.cpp)) 

xdata_obj = $(patsubst %.cpp, %.o, $(wildcard ./src/xdata_server/*.cpp)) 
xdata_cache_obj = $(patsubst %.cpp, %.o, $(wildcard ./src/xdata_server/data_cache/*.cpp)) 
xdata_server_obj = $(common_obj) $(xdata_obj) $(xdata_cache_obj)

xgame_obj = $(patsubst %.cpp, %.o, $(wildcard ./src/xgame_server/*.cpp)) 
xgame_map_obj = $(patsubst %.cpp, %.o, $(wildcard ./src/xgame_server/map/*.cpp)) 
xgame_player_obj = $(patsubst %.cpp, %.o, $(wildcard ./src/xgame_server/player/*.cpp)) 
xgame_lua_obj = $(patsubst %.cpp, %.o, $(wildcard ./src/xgame_server/lua/*.cpp)) 
xgame_task_obj = $(patsubst %.cpp, %.o, $(wildcard ./src/xgame_server/task/*.cpp)) 
xgame_battle_obj = $(patsubst %.cpp, %.o, $(wildcard ./src/xgame_server/battle/*.cpp)) 
xgame_server_obj = $(common_obj) $(xgame_obj) $(xgame_map_obj) $(xgame_player_obj) $(xgame_task_obj) $(xgame_lua_obj) $(xgame_battle_obj)

xgate_server_obj = $(common_obj) $(patsubst %.cpp, %.o, $(wildcard ./src/xgate_server/*.cpp)) 

%.o:%.cpp
	$(CC) -c $(CFLAGS) $(INC_DIR) $< -o $@

all : xdata_server xgame_server xgate_server

xdata_server : $(xdata_server_obj)
	$(CC) $(CFLAGS) $(LIB_DIR) $(xdata_server_obj) -o xdata_server $(LIBS)
	
xgame_server : $(xgame_server_obj)
	$(CC) $(CFLAGS) $(LIB_DIR) $(xgame_server_obj) -o xgame_server $(LIBS) -Wl,--hash-style=sysv

xgate_server : $(xgate_server_obj)
	$(CC) $(CFLAGS) $(LIB_DIR) $(xgate_server_obj) -o xgate_server $(LIBS)

clean :
	rm -rf $(xdata_server_obj) $(xgame_server_obj) $(xgate_server_obj) xdata_server xgame_server xgate_server
	